package com.dcdata.jt809server.head.impl;

import com.dcdata.jt809server.common.consts.BusinessDataType;
import com.dcdata.jt809server.common.consts.EncryptFlag;
import com.dcdata.jt809server.common.consts.MsgSn;
import com.dcdata.jt809server.common.consts.UserInfo;
import com.dcdata.jt809server.packet.BasePacket;
import com.dcdata.jt809server.packet.TrafficHeartbeatResponsePacket;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;

/**
 * program: JT809Server
 * description: 心跳包发送
 * @author DCDATA
 * @date 2020-03-19 16:51
 **/
@Slf4j
public class TrafficHeartbeatHandler extends SimpleChannelInboundHandler<TrafficHeartbeatResponsePacket> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TrafficHeartbeatResponsePacket msg) {
        msg.setMsgLength(BasePacket.getFixedByteLength());
        msg.setMsgSn(MsgSn.getMsgSN());
        msg.setMsgId(BusinessDataType.UP_LINKTEST_RSP);
        msg.setMsgGNSSCenterId(UserInfo.MSG_GNSSCENTERID);
        msg.setVersionFlag(new byte[]{1, 0, 0});
        msg.setEncryptFlag(EncryptFlag.NO);
        msg.setEncryptKey(0);

        log.info("心跳包响应内容：{}", msg);
        ctx.channel().writeAndFlush(msg);
    }
}
